﻿using MVCManage.Model;
using MVCManage.Model.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MVCMamage.DAL;
namespace MVCManage.BLL
{
    public class AuthorityBLL : BaseBLL<Authority>
    {
        public override void SetDal()
        {
            Dal = new AuthorityDAL();
        }
        public bool Add(int rid, int[] ids)
        {
            List<Authority> list = new List<Authority>();
            foreach (int aid in ids)
            {
                Authority auth = new Authority()
                {
                    authID = 0,
                    roleID = rid,
                    menuID = aid,
                    sort = 0,
                    lastTime = DateTime.Now
                };
                list.Add(auth);
            }
            Dal.Add(list);
            return Dal.SaveChanges();

        }
        public List<Authority> GetAuthByid(int rid)
        {
            var list = Dal.Query().Where(n => n.roleID == rid);
            return list.ToList();
        }

        public bool Deletes(int rid) {
            var zhi = Dal.Query().Where(n => n.roleID == rid).ToList();
            Dal.Deletes(zhi);
            return Dal.SaveChanges();
        
        }

        public bool Delete(int id) {
            var zhi = Dal.Query().Where(n => n.menuID == id).FirstOrDefault();
            Dal.Delete(zhi);
            return Dal.SaveChanges();
        }


    }
}
